/**
 * rem 调整，尺寸也要调整
 * @param {Object} width
 */

var checkCard = (function() {
	function checkcard(option) {
		this.target = option.target
		this.data = option.data;
		this.callbackf = option.callbackf? option.callbackf :function(){};
		this.valuetarget = option.valuetarget
		this._bindEvent()
		
	}

	checkcard.prototype = {
		_bindEvent() {
			var _this = this;
			$(this.target).click(function() {
				_this._creatHtml()
			})
		},
		_creatHtml() {
			var _this = this
			var alertDom = document.createElement("div");
			alertDom.id = "check"
			var htm = ""
			this.data.forEach(function(eleme) {
				htm += "<span data-value='" + eleme.value + "'>" + eleme.text + "</span>"
			})
			alertDom.innerHTML = "<div class='content_box'>" + htm + "</div>"
			document.body.appendChild(alertDom);
			$('.content_box>span').click(function(event) {
				event.stopPropagation()
				$(this).addClass('active')
				$(_this.target).val($(this).text())
				$(_this.target).text($(this).text()) 
				if($(this).text()=="额度2400以上"){
					$(_this.target).text('2400以上')
				}
				if($(this).text()=="额度2400以下"){
					$(_this.target).text('2400以下')
				}
				$(_this.valuetarget).val($(this).attr('data-value'))
				setTimeout(function(){
					_this._hide()
				},0)
				_this.callbackf()
			})
			$("#check").click(function(){
				_this._hide()
			})
		},
		_hide(alertDom) {
			$("#check").remove()
		}

	}
	return checkcard;
})()